<?php

/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace common\rest\controllers;

use common\rest\controllers\Controller as BaseController;
use yii\helpers\ArrayHelper;

/**
 * Controller is the base class for RESTful API controller classes.
 *
 * Controller implements the following steps in a RESTful API request handling cycle:
 *
 * 1. Resolving response format (see [[ContentNegotiator]]);
 * 2. Validating request method (see [[verbs()]]).
 * 3. Authenticating user (see [[\yii\filters\auth\AuthInterface]]);
 * 4. Rate limiting (see [[RateLimiter]]);
 * 5. Formatting response data (see [[serializeData()]]).
 *
 * For more details and usage information on Controller, see the [guide article on rest controllers](guide:rest-controllers).
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class AuthController extends BaseController {

    public function behaviors() {
        return ArrayHelper::merge(parent::behaviors(), [
                    'authenticator' => [
                        'class' => \common\rest\filters\auth\CompositeAuth::className(),
                        'authMethods' => [
                            \common\rest\filters\auth\HttpBearerAuth::className(),
                            // \common\rest\filters\auth\QueryParamAuth::className(),
                        ],
                    ],
                    'access' => [
                        'class' => \yii\filters\AccessControl::className(),
                        'rules' => [
                            [
                                'actions' => ['login',],
                                'allow' => true,
                            ],
                            [
                                'roles' => ['@'],
                                'allow' => true,
                            ],
                        ],
                    ],
        ]);
    }

}
